package com.googlecode.gunncs.controller;

import com.googlecode.grtframework.core.GRTLoggedProcess;
import com.googlecode.gunncs.actuator.RobotBase;
import com.googlecode.gunncs.event.RangeFinderEvent;
import com.googlecode.gunncs.event.RangeFinderListener;
import com.googlecode.gunncs.sensor.RangeFinder;

/**
 * 
 * @author ajc
 * 
 */
public class StopAtDistance extends GRTLoggedProcess implements
		RangeFinderListener {

	private final RobotBase base;
	private final RangeFinder r;

	public StopAtDistance(RobotBase base, RangeFinder r, float d, String name) {
		super(name);
		this.base = base;
		this.r = r;
	}

	@Override
	public void distanceChanged(RangeFinderEvent e) {

		base.drive(.1, 0);
		if (e.getId() == 2) {
			System.out.println(e);
		}
	}

	@Override
	public void initiate() {
		super.initiate();
		r.addListener(this);
	}

	@Override
	public void terminate() {
		super.terminate();
		r.removeListener(this);
	}
}
